package com.niit.blog.entity.MyEnum;

import lombok.Getter;

@Getter
public enum IsDeletedFlagEnum {
    DELETED(1,"已删除"),
    UN_DELETED(0,"未删除");

    public int code;

    public String desc;

    IsDeletedFlagEnum(int code, String desc){
        this.code = code;
        this.desc = desc;
    }
    //该方法IsDeletedFlagEnum.values()是自带的方法，作用是拿到自己定义的枚举值
    //IsDeletedFlagEnum.values()中IsDeletedFlagEnum是定义的枚举类名，values则是找到规定枚举类中自定的枚举
    public static IsDeletedFlagEnum getByCode(int codeVal){
        for(IsDeletedFlagEnum resultCodeEnum : IsDeletedFlagEnum.values()){
            //判断外部给的code对应哪一个枚举类然后返回
            if(resultCodeEnum.code == codeVal){
                return resultCodeEnum;
            }
        }
        return null;
    }

}
